package com.clothing.dao.impl;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.stereotype.Repository;

import com.clothing.dao.LeaveMessageReplyDao;
import com.clothing.entity.LeaveMessageReply;

/**
 * @ClassName: LeaveMessageReplyDaoImpl 
 * @Description: TODO(Dao) 
 * @author Charles.Tao 
 * @date 2017年9月6日 下午3:40:20 
 * @version 1.0
 */
@Repository
public class LeaveMessageReplyDaoImpl extends BaseDaoImpl<LeaveMessageReply, Long> implements LeaveMessageReplyDao
{
    @Override
    public List<LeaveMessageReply> findNewMessage(Long leaveMessageId, Long lastMessageId)
    {
        CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
        CriteriaQuery<LeaveMessageReply> criteriaQuery = criteriaBuilder
            .createQuery(LeaveMessageReply.class);
        Root<LeaveMessageReply> root = criteriaQuery.from(LeaveMessageReply.class);
        criteriaQuery.select(root);
        Predicate predicate = criteriaBuilder.and(criteriaBuilder
            .greaterThan(root.get("id"), lastMessageId), criteriaBuilder
            .equal(root.get("leaveMessage").get("id"), leaveMessageId));
        criteriaQuery.where(predicate);
        
        return findList(criteriaQuery, null, null, null, null);
    }
}
